#!/bin/bash
# Zaitan Module - Nagios FrontEnd Install
# Zaitan Team <http://code.google.com/p/zaitan/>
# Script Tirado desse link http://www.nagiosql.org/wiki/Documentation


RMOD_ENGINE='1.0'
RMOD_CATEGORY='Software'
RMOD_SUBCATEGORY='Servers'
RMOD_NAME='Nagios FrontEnd'
RMOD_AUTHOR='Zaitan Team'
RMOD_VERSION='2.0.0'
RMOD_DESCRIPTION='Installs Nagios'



# Install Nagios FrontEnd

echo Running $RMOD_NAME...
#/usr/lib/zaitan/modulo/mod-checkInstall

cd /usr/share/zaitan

apt-get update
apt-get -y install apache2
apt-get -y install mysql-server
apt-get -y install php5-gd 
apt-get -y install libgd-dev 
apt-get -y install php5-mysql 
apt-get -y install libsnmp9-dev 
apt-get -y install libc6-dev 
apt-get -y install libmysqlclient15-dev 
apt-get -y install build-essential
apt-get -y install php-pear
pear install HTML_Template_IT

echo '<Directory  /var/www/nagiosQL>
  <FilesMatch \.(?i:ini)$>
    Order allow,deny
    Deny from all
  </FilesMatch>
</Directory>' > nagiosQL
cp nagiosQL /etc/apache2/sites-enabled/


## FrontEnd Web para o Nagios
wget -c http://ufpr.dl.sourceforge.net/sourceforge/nagiosql/nagiosql-2.00-P00.tar.gz
tar zxvf nagiosql-2.00-P00.tar.gz
mv nagiosQL /var/www
cd /var/www/nagiosQL/config

## Criar um banco no mysql
mysqladmin -u root password 123
mysql -uroot -p < nagiosQL_v2_db_mysql.sql


chown -R nagios:nagios /var/www/nagiosQL

## Mudar o usuario do apache2 para nagios e Grupo nagcmd
#gedit /etc/apache2/apache.conf 
sed -i 's/^User.*/User nagios/' /etc/apache2/apache2.conf
sed -i 's/^Group.*/Group nagcmd/' /etc/apache2/apache2.conf

/etc/init.d/apache2 restart
echo $RMOD_NAME Finibashed...

##Logs
echo $RMOD_NAME-$RMOD_VERSION | tee -a /usr/share/zaitan/logs
/usr/lib/zaitan/modulo/mod-logs
##

exit 0
